package com.wyj.wuliwuli.controller;

import com.wyj.wuliwuli.common.AjaxRequest;
import com.wyj.wuliwuli.common.AjaxResult;
import com.wyj.wuliwuli.common.PageParam;
import com.wyj.wuliwuli.entity.WuliVideo;
import com.wyj.wuliwuli.service.WuliVideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Api(tags = "视频")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/wuli-video")
public class WuliVideoController {

    private final WuliVideoService wuliVideoService;

    /**
     * 如果使用默认排序方式，ajaxRequest.data.property可以不传值
     * 如果按点赞量倒序排列， ajaxRequest.data.property = "likeCount"
     * @param ajaxRequest
     * @return
     */
    @ApiOperation(value = "分页查询")
    @PostMapping("/page")
    public AjaxResult page(@RequestBody AjaxRequest<PageParam> ajaxRequest) {
        return wuliVideoService.page(ajaxRequest);
    }

    @ApiOperation(value = "根据id查询")
    @GetMapping("/{id}")
    public AjaxResult getById(@PathVariable Long id) {
        return wuliVideoService.getById(id);
    }

    @ApiOperation(value = "根据用户id查询视频")
    @GetMapping("/user/{userId}")
    public AjaxResult getByUserId(@PathVariable Long userId) {
        return wuliVideoService.getByUserId(userId);
    }

    @ApiOperation(value = "保存")
    @PostMapping("/save")
    public AjaxResult save(@RequestBody AjaxRequest<WuliVideo> ajaxRequest) {
        return wuliVideoService.save(ajaxRequest);
    }

    @ApiOperation(value = "根据id删除")
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable Long id) {
        return wuliVideoService.deleteById(id);
    }
    @ApiOperation(value = "根据审核状态查询")
    @GetMapping("/audit-status")
    public AjaxResult getByAuditStatus() {
        return wuliVideoService.getByAuditStatus();
    }

    @ApiOperation(value = "根据id审核")
    @GetMapping("/audit/{id}")
    public AjaxResult auditById(@PathVariable Long id) {
        return wuliVideoService.auditById(id);
    }


}
